# barco/binrepos.py

import getpass
import xmlrpclib
import httplib
import threading
import SimpleXMLRPCServer

from . import error

class Client(object):

    class WorkSpace(object):

        def __init__(self, server, directory, branch):
            return None

        def create(self):
            return self

        def update(self):
            return self

        def read_module_desc(self, module):
            return None
        
        def has_module_desc(self, module):
            return False

    def __init__(self):      
        self.server = xmlrpclib.ServerProxy('http://localhost:4243/')
        return None

    def list_tags(self, *args):
        for t in self.server.list_tags(): 
            print 'uuid=\'%s\' owner=\'%s\' time=%s' % (t['uuid'], t['user'], t['time'])
        return None

    def create_tag(self, user=getpass.getuser()):
        tag = self.server.create_tag(user)
        print 'binary tag \'%s\' created.' % tag
        return None

    def create_workspace(self, directory, branch):
        return Client.WorkSpace(self.server, directory, branch).create()

    def update_workspace(self, directory, branch):
        return Client.WorkSpace(self.server, directory, branch).update()


